from openpyxl import load_workbook
import pymysql

config = {
    'host': '127.0.0.1',
    'port': 3306,
    'user': 'root',
    'password': 'mysql',
    'charset': 'utf8',
    # 'cursorclass': pymysql.cursors.DictCursor

}
conn = pymysql.connect(**config)
conn.autocommit(1)
cursor = conn.cursor()
name = 'exam'
cursor.execute('create database if not exists %s' % name)
conn.select_db(name)
table_name = 'exam_info1'
cursor.execute(
    'create table if not exists %s(id MEDIUMINT NOT NULL AUTO_INCREMENT,questions varchar(256),answers varchar(5),options varchar(256),primary key (id))' % table_name)

wb2 = load_workbook('timu1.xlsx')
ws = wb2.get_sheet_names()
for row in wb2:
    print("1")
    for cell in row:
        value1 = (cell[0].value, cell[1].value, cell[2].value)
        cursor.execute('insert into exam_info1 (questions,answers,options) values(%s,%s,%s)', value1)

print("overing...")
# for row in A:
# 	print(row)
# print (wb2.get_sheet_names())
